<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>GEN18</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="ScoregensTop.html" title="Score Statements and GEN Routines" />
    <link rel="prev" href="GEN17.html" title="GEN17" />
    <link rel="next" href="GEN19.html" title="GEN19" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">GEN18</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="GEN17.html">Prev</a> </td>
          <th width="60%" align="center">Score Statements and GEN Routines</th>
          <td width="20%" align="right"> <a accesskey="n" href="GEN19.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="GEN18"></a>
      <div class="titlepage"></div>
      <a id="IndexGEN18" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">GEN18</span>
        </h2>
        <p>GEN18 — 
      Writes composite waveforms made up of pre-existing waveforms.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp214670864"></a>
        <h2>Description</h2>
        <p>
      Writes composite waveforms made up of pre-existing waveforms. Each contributing waveform requires 4 pfields and can overlap with other waveforms.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp214734800"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size 18 fna ampa starta finisha fnb ampb startb finishb ...</pre>
      </div>
      <div class="refsect1">
        <a id="idp214736752"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>size</em></span> -- number of points in the table. Must be a power-of-2 (see <a class="link" href="f.html" title="f Statement (or Function Table Statement)">f</a> statement).
    </p>
        <p>
      <span class="emphasis"><em>fna, fnb, etc.</em></span> -- pre-existing table number to be written into the table.
    </p>
        <p>
      <span class="emphasis"><em>ampa, ampb, etc.</em></span> -- strength of wavefoms. These are relative strengths, since the composite waveform may be rescaled later. Negative values are permitted and imply a 180 degree phase shift.
    </p>
        <p>
      <span class="emphasis"><em>starta, startb, etc.</em></span> -- where to start writing the fn into the table.
    </p>
        <p>
      <span class="emphasis"><em>finisha, finishb, etc.</em></span> -- where to stop writing the fn into the table. The last available location is the power of two - 1.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp214742816"></a>
        <h2>Examples</h2>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
<span class="stamnt">f</span> 1  0  4096  10  1
<span class="stamnt">f</span> 2  0  1024  18  1  1  0  511  1  1  512  1023</pre>
        </div>
        <p>

      f2 consists of two copies of f1 written in to locations 0-511 and 512-1023.
    </p>
        <p>
	    Here is an example of the GEN18 routine. It uses the files <a class="ulink" href="examples/gen18.csd" target="_top"><em class="citetitle">gen18.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp214747616"></a>
          <p class="title">
            <strong>Example 1108. An example of the GEN18 routine.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac  <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o gen18.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

ifn   <span class="op">=</span> p4  
ilen  <span class="op">=</span> <span class="opc">ftlen</span>(ifn)
aphase  <span class="opc">phasor</span> 220 
asig    <span class="opc">tablei</span> aphase<span class="op">*</span>ilen, ifn
        <span class="opc">outs</span>   asig, asig
      
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">f</span> 1 0 4096 10 1                                         <span class="comment">;sine</span>
<span class="stamnt">f</span> 2 0 4096 10 1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111  <span class="comment">;sawtooth</span>
<span class="stamnt">f</span> 3 0 4096 11 10 5 2                                    <span class="comment">;cosine partials</span>

<span class="stamnt">f</span> 11 0 8192  18 1 1 0 4095 2 1 4096 8191    <span class="comment">;sine+sawtooth</span>
<span class="stamnt">f</span> 12 0 8192  18 1 1 0 4095 3 1 4096 8191    <span class="comment">;sine+cosine partials</span>
<span class="stamnt">f</span> 13 0 1024  18 1 0.7 0 767 3 0.7 512 1023  <span class="comment">;sine+cosine partials overlapped, shorter table</span>

<span class="stamnt">i</span> 1 0 2 2    <span class="comment">;play sawtooth </span>
<span class="stamnt">i</span> 1 + 2 3    <span class="comment">;then cosine partials</span>
<span class="stamnt">i</span> 1 5 2 11   <span class="comment">;now sine+sawtooth</span>
<span class="stamnt">i</span> 1 + 2 12   <span class="comment">;and sine+cosine partials</span>
<span class="stamnt">i</span> 1 + 2 13   <span class="comment">;and sine+cosine partials overlapped, shorter table</span>

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

        <span class="phrase">These are the diagrams of the waveforms generated by GEN18, as used in the example:</span>

      </p>
        <div class="mediaobject">
          <img src="images/gen18_1.png" />
          <div class="caption">
            <p>f 11 0 8193 18 1 1 0 4096 2 1 4097 8192 - composite waveform made up of a sine wave and a sawtooth</p>
          </div>
        </div>
        <p>

      </p>
        <div class="mediaobject">
          <img src="images/gen18_2.png" alt="f 12 0 8192 18 1 1 0 4096 3 1 4097 8192 - composite waveform made up of a sine wave and a wave of cosine partials" />
          <div class="caption">
            <p>f 12 0 8192  18 1 1 0 4096 3 1 4097 8192 - composite waveform made up of a sine wave and a wave of cosine partials</p>
          </div>
        </div>
        <p>

      </p>
        <div class="mediaobject">
          <img src="images/gen18_3.png" alt="f 13 0 1024 18 1 0.7 0 767 3 0.7 512 1023 - sine+cosine partials overlapped, also shorter table than f12" />
          <div class="caption">
            <p>f 13 0 1024  18 1 0.7 0 767 3 0.7 512 1023 - sine+cosine partials overlapped, also shorter table than f12</p>
          </div>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp214760288"></a>
        <h2>Deprecated Names</h2>
        <p>
      <span class="emphasis"><em>GEN18</em></span> was called <span class="emphasis"><em>GEN22</em></span> in version 4.18. The name was changed due to a conflict with DirectCsound.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp214762432"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: William <span class="quote">“<span class="quote">Pete</span>”</span> Moss</td>
          </tr>
          <tr>
            <td>University of Texas at Austin</td>
          </tr>
          <tr>
            <td>Austin, Texas USA</td>
          </tr>
          <tr>
            <td>January 2002</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 4.18, changed in version 4.19</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="GEN17.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="ScoregensTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="GEN19.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">GEN17 </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> GEN19</td>
        </tr>
      </table>
    </div>
  </body>
</html>
